package Test;
import java.util.*;
public class test2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();//节点个数
        int m = scanner.nextInt();//边的个数
        //存储每个节点的入度
        int[] inDegree = new int[n + 1 ];
        //存储图的邻接表
        List<List<Integer>> graph = new ArrayList<>(n + 1);
        //初始化邻接表
        for (int i = 0; i <= n ; i++) {
            graph.add(new ArrayList<>());
        }
        //读取边并且构件图
        for (int i = 0; i < m; i++) {
            int u = scanner.nextInt();
            int v = scanner.nextInt();
            graph.get(u).add(v);
            inDegree[v]++;
        }
        scanner.close();
        //拓扑排序

        List<Integer> result = topolong(graph,inDegree,n);
//        if (result == null) {
//            System.out.println(-1);
//        }else {
            for (int num : result) {
                System.out.print(num + " ");
            }
        }



        private static List<Integer> topolong(List<List<Integer>> graph, int[] inDegree, int n) {

            Queue<Integer> queue = new LinkedList<>();
            //将所有入度为0的节点入队
            for (int i = 0; i <= n; i++) {
                if (inDegree[i] == 0) {
                    queue.offer(i);
                }
            }
            List<Integer> result = new ArrayList<>();
            while (!queue.isEmpty()) {
                int u = queue.poll();
                result.add(u);
                //遍历u的所有邻节点v
                for (int v : graph.get(u)) {
                    //将v的入度减1
                    inDegree[v]--;
                    //如果v的入度减为0，则将其入队
                    if (inDegree[v] == 0) {
                        queue.offer(v);
                    }
                }
            }
            //如果结果中的节点不等于n，说明有环，无法拓扑排序
            if (result.size() != n) {
                return null;
            }
                return result;


        }

}




